package com.haoshuang.zhouzhoubang.ui.page.welfare.insure

import com.haoshuang.zhouzhoubang.model.api.ApiRepo
import com.haoshuang.zhouzhoubang.model.bean.InsureApplyRecordBean
import com.haoshuang.zhouzhoubang.model.bean.InsureUseRecordBean
import com.haoshuang.zhouzhoubang.model.bean.ShopWelfareRecordBean
import com.mufeng.libs.base.BaseViewModel
import com.mufeng.libs.net.netRequest
import com.mufeng.libs.state.StateData
import com.mufeng.libs.state.StatefulMutableLiveData

class InsureWelfareActivityViewModel : BaseViewModel() {



    /**
     * 获取保险使用记录
     */
    val getInsureUseRecordData = StatefulMutableLiveData<MutableList<InsureUseRecordBean>>()
    fun getInsureUseRecord(page: Int) = netRequest {
        start { getInsureUseRecordData.value = StateData.Loading }
        request { ApiRepo.getInsureUseRecord(page)  }
        success { getInsureUseRecordData.value = StateData.Success(it.data) }
        error { code, msg ->
            getInsureUseRecordData.value = StateData.Error(code, msg)
        }
    }

    /**
     * 商城使用记录
     */
    val getGoodsWelfareLogData = StatefulMutableLiveData<MutableList<ShopWelfareRecordBean>>()
    fun getGoodsWelfareLog(welfare_id: Int?, page: Int) = netRequest {
        start { getGoodsWelfareLogData.value = StateData.Loading }
        request { ApiRepo.getGoodsWelfareLog(welfare_id, page) }
        success { getGoodsWelfareLogData.value = StateData.Success(it.data) }
        error { code, msg ->
            getGoodsWelfareLogData.value = StateData.Error(code, msg)
        }
    }

}